package com.xhdx;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

@SuppressWarnings("serial")
public class TransientTest implements java.io.Serializable {
    private Date loggingDate = new Date();
    private String uid;
    private transient String pwd;

    public TransientTest(String user, String password) {
        uid = user;
        pwd = password;
    }

    public String toString() {
        String password = null;
        if (pwd == null) {
            password = "";
        } else {
            password = pwd;
        }
        return String.format("%s%s%s%s%s%s", "user=", uid, "; logging date=", loggingDate.toString(), "; password=",
                password);
    }
    
    public static void test(){
        TransientTest transientTest = new TransientTest("XIAO", "_PASSWORD");
        System.out.println(transientTest.toString());
        ObjectOutputStream o = null;
        try {
            o = new ObjectOutputStream(new FileOutputStream("d:\\transientTest.out"));
            o.writeObject(transientTest);
        } catch (Exception e) {
        }finally{
            try {
                o.close();
            } catch (IOException e) {
            }
        }
        try {
            ObjectInputStream in = new ObjectInputStream(new FileInputStream("d:\\transientTest.out"));
            transientTest = (TransientTest) in.readObject();
            System.out.println(transientTest.toString());
        } catch (Exception e) {
        }
    }
    public static void main(String args[]) {
        test();
    }
}
